var miniCost = function(costs,days){

  var maxDay =days[days.length-1]
  console.log(maxDay)

  const dp = new Array(maxDay+1).fill(0)
  console.log(dp.length)



  const travelDays = new Set(days);

  for(let i=1;i<=maxDay;i++){
    if(!travelDays.has(i)){
      dp[i] = dp[i-1];
      continue;
    }

   let oneDay = dp[i-1]+ costs[0]


   let threeDay = (i>=3?dp[i-3]:0)+ costs[1]
   let sevenDay = (i>=7?dp[i-7]:0)+ costs[2]
   let monthDay = (i>=30?dp[i-30]:0)+ costs[3]
   dp[i] = Math.min(oneDay,threeDay,sevenDay,monthDay)
  }

  console.log(dp)

  return dp[maxDay]

}

var money = [5,14,30,100]

var days = [1,3,15,20,21]

const res = miniCost(money,days)

console.log(res)

